package com.wondersgroup.controller;

import com.wondersgroup.entity.Record;
import com.wondersgroup.service.CompanyService;
import com.wondersgroup.service.RecordService;
import com.wondersgroup.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RequestMapping("/record")
@RestController
public class RecordController {


  @Autowired
  private RecordService recordService;

  @Autowired
  private CompanyService companyService;




  @RequestMapping("/addRecord")
  public Map<String, Object> addRecord(HttpServletRequest request) {
    String dwid = request.getParameter("dwid");
    Map<String, Object> map = new HashMap<>();
    Record record = new Record();
    record.setId(UUID.randomUUID().toString().replace("-", ""));//UUid生成
    record.setDwid(dwid);
    record.setOpenId("1234");
    record.setSjhm("1234");
    record.setXm("ttt");
    record.setXb("1");
    record.setZjlx("1");
    record.setTw(33.3f);
    record.setLfsy("");
    record.setLfsyqt(null);
    record.setTxrs(0);
    record.setBz("1234");
    record.setDjsj(TimeUtil.getSomeDay(new Date(),-1));
    try {
      recordService.addRecord(record);
      map.put("code", 200);
      map.put("msg", "添加成功!");
    } catch (Exception e) {
      e.printStackTrace();
      map.put("code", 500);
      map.put("msg", "添加异常!");
      return map;
    }
    return map;
  }


  @RequestMapping("/getAllRecords")
  public List<Record> getAllrecords() {
    return recordService.getAllRecords();

  }

}
